package handler

import (
	pkg2 "api/pkg"
	"github.com/gin-gonic/gin"
	"net/http"
	"path"
)

func Upload(c *gin.Context) {
	file, m, err := c.Request.FormFile("img")
	if err != nil {
		return
	}
	ext := path.Ext(m.Filename)
	if ext != "MP4" {
		c.JSON(http.StatusOK, gin.H{
			"code": "400",
			"msg":  "发布成功",
			"data": nil,
		})
		return
	}
	if m.Size > 1*1024*1024 {
		c.JSON(http.StatusOK, gin.H{
			"code": "400",
			"msg":  "文件不能大于5mb",
			"data": nil,
		})
		return
	}

	upload, err := pkg2.Upload(file, m)
	if err != nil {
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": "200",
		"msg":  "发布成功",
		"data": upload,
	})
}
